/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package customGuiControl;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import javax.swing.JPanel;

/**
 *
 * @author emilio
 */
public class textPanel extends JPanel {
    private Float scaleFontFatt=null;
    private Float fontPreferredSize=40f;
    private Float FontScale=null;
    private Float realFontSize=null;
    private String text;

    public textPanel(String text){
        super();
        this.text=text;
    }
    
    public void setTextOnPanel(String str){
        
        this.text= str;
        this.repaint();
        
    }
    

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D g2= (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			    RenderingHints.VALUE_ANTIALIAS_ON);
        if(this.FontScale==null)
        {
            this.FontScale=new Float(this.getHeight())/this.fontPreferredSize;
        }
        this.realFontSize=new Float(this.getHeight())/this.FontScale;
        Font font = new Font("Droid Sans",Font.LAYOUT_LEFT_TO_RIGHT+Font.BOLD, this.realFontSize.intValue());
        Rectangle2D rect = font.getStringBounds(this.text, new FontRenderContext(null, true, false));
        g2.setFont(font);
        g2.setColor(Color.black);
        g2.setFont(font);
        g2.drawString(this.text,
                       new Float(this.getWidth()/2-rect.getWidth()/2),
                       new Float(this.getHeight()/2+rect.getHeight()/4).intValue());
    }
}
